package com.nxcy.caculator;

import com.nxcy.caculator.oper.Operation;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Scanner;

public class Caculator5 {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入第一个操作数");
        double num1 = sc.nextInt();
        System.out.println("请输入操作符");
        String oper = sc.next();
        System.out.println("请输入第二个操作数");
        double num2 = sc.nextInt();
        double result = 0;
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        Operation operation = (Operation) context.getBean(oper);
        result = operation.caculate(num1, num2);
        System.out.println(num1 + oper + num2 + "=" + result);
    }
}
